package com.hotel.customersystem.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hotel.customersystem.pojo.Kudos;
import com.hotel.customersystem.service.KudosService;
import com.hotel.customersystem.mapper.KudosMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
* @author magtop
* @description 针对表【kudos】的数据库操作Service实现
* @createDate 2022-11-07 18:22:09
*/
@Service
public class KudosServiceImpl extends ServiceImpl<KudosMapper, Kudos>
    implements KudosService{
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public boolean hasKudos(String commentId, String userId) {
        String commentRedisId = "kudos:"+commentId;
        boolean has = redisTemplate.opsForSet().isMember(commentRedisId,userId);
        return has;
    }

    @Override
    public boolean doKudos(String commentId, String userId) {
        String commentRedisId = "kudos:"+commentId;
        Long result = redisTemplate.opsForSet().add(commentRedisId,userId);
        return result>0;
    }

    @Override
    public boolean undoKudos(String commentId, String userId) {
        String commentRedisId = "kudos:"+commentId;
        Long result = redisTemplate.opsForSet().remove(commentRedisId,userId);
        return result>0;
    }

    @Override
    public Long kudosNum(String commentId) {
        String commentRedisId = "kudos:"+commentId;
        Long num = redisTemplate.opsForSet().size(commentRedisId);

        return num;
    }

}




